package com.cedancp.hometrade;

import library.UserFunctions;

import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.MenuItem;

public class MostrarMapa extends FragmentActivity {
	
	private GoogleMap map;
	String cod_publicacion;
	UserFunctions userFunction=new UserFunctions();
	LatLng ubicacion;
	String titulo;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_mostrar_mapa);
		cod_publicacion=getIntent().getExtras().getString("cod_publicacion");
		titulo=getIntent().getExtras().getString("titulo");
		ubicacion=(LatLng) getIntent().getExtras().get("ubicacion");
		map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
		map.setMyLocationEnabled(true);
		map.addMarker(new MarkerOptions().position(ubicacion).title(titulo));
		CameraUpdate update=CameraUpdateFactory.newLatLngZoom(ubicacion, 16);
		map.animateCamera(update);
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.mostrar_mapa, menu);
		return true;
	}
	
	//Creando los eventos de las opciones de menu
	@Override
    public boolean onOptionsItemSelected(MenuItem item){
		UserFunctions userFunction= new UserFunctions();
    	switch (item.getItemId()) {
		case R.id.mnu_salir:
			if(userFunction.logoutUser(getApplicationContext())){
				Intent mainActivity=new Intent(getApplicationContext(), MainActivity.class);
				mainActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(mainActivity);
			}
			
			return true;
			
		case R.id.mnu_cuenta:
				Intent iCuenta =new Intent(getApplicationContext(), AdministrarCuenta.class);
				startActivity(iCuenta);
				return true;
				
		case R.id.acercaDe:
			Intent iAcercaDe = new Intent(getApplicationContext(), AcercaDe.class);
			startActivity(iAcercaDe);
			return true;

		default:
			return super.onOptionsItemSelected(item);
		}
    }

}
